package com.example.demo.listener;

import com.example.demo.event.MyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

@EnableAsync
@Component
public class MyAnnotationListener {

    @EventListener
    public void listener1(MyEvent event) {
        System.out.println("注解监听器1:" + event.getMsg());
    }

//    @EventListener
//    @Async
//    public void listener2(MyEvent event) {
//        try {
//            Thread.sleep(3000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        System.out.println("注解监听器2:" + event.getMsg());
//    }
}